export let gotoDetail = {
  methods: {
    gotoDetail(id) {
      if(id === null || id === undefined) {
        vm.$router.push({ name: 'homePage', params: { field: vm.$store.state.defaultField }});
      }
      const vm =this;
      vm.$router.push({ name: 'detail', params: { id }});
    }
  }
}

export let geneDetailRoute = {
  methods: {
    geneDetailRoute(id) {
      const vm =this;
      if(id === null || id === undefined) {
        return { name: 'homePage', params: { field: vm.$store.state.defaultField} };
      }
      return { name: 'detail', params: { id } };
    }
  }
}

export let gotoHome = {
  methods: {
    gotoHome(field) {
      const vm = this;
      if (vm.$route.params.field !== field) {
        vm.$router.push({ name: 'homePage', params: { field }});
      } else {
        window.location.reload();
      }
    }
  }
}

export let fieldState = {
  computed: {
    field() {
      return this.$store.state.field;
    }
  },
  methods: {
    /**
     * 提交到state
     */
    commitField(field) {
      const vm = this;
      if (field === undefined || field === null) {
        field = vm.field;
      }
      vm.$store.commit('SETFIELD', field);
    }
  }
}
